import axios from "axios"
import store from '../../store'
import {
	baseURL
} from '../../env'
const request = (method, url, data = {}) => {
	url = /^\//.test(url) ? url : `/${url}`
	return new Promise(function (resolve, reject) {
		axios({
			method,
			url,
			data,
			baseURL,
			headers: {
				'token': store.getters.token,
			}
		}).then((response) => { //这里使用了ES6的语法
			resolve(response.data)
		}).catch((error) => {
			reject(error)
		})
	})
}

function Get(url, data) {
	return request('get', url, data)
}

function Post(url, data) {
	return request('post', url, data)
}
export default {
	Get,
	Post
}
